<template>
  <a-modal :open="open" width="700px" title="修改信息" centered @ok="onOk" @cancel="onCancel">
    <PatientInfoForm v-model:value="formState" />
  </a-modal>
</template>
<script setup>
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import { get, post } from '@/utils/request'
import PatientInfoForm from '@/components/business/PatientInfoForm'

const emit = defineEmits(['update:open', 'update:value', 'success'])
const props = defineProps({
  open: Boolean,
  rowData: {
    type: Object,
    default: () => ({})
  }
})
const formState = ref({})

const getPatientInfo = async () => {
  const { code, data } = await get('/common/patient/getPatientInfo?br_id=' + props.rowData.brId)
  if (code !== 0) return
  formState.value = data
}

watch(
  () => props.open,
  (val) => {
    val && getPatientInfo()
  }
)

const onOk = async () => {
  const res = await post('/common/patient/savePatientInfo', formState.value)
  if (res.code === 0) {
    message.success('保存成功')
    emit('success')
  } else {
    message.error(res.msg || '保存失败')
  }
}

const onCancel = () => {
  emit('update:open', false)
}
</script>
<style lang="less" scoped></style>
